<?php


namespace Swb\Shop\Helper;


use Hyperf\DbConnection\Db;
use Swb\Shop\Model\CBrandAlliance;
use Swb\Shop\Model\SysDataDict;

trait BrandTrait
{
	public function get_active_brand($id)
	{
		$data = CBrandAlliance::query()
			->where('id',$id)
			->select('brand_name','file_id','brand_location',
				'min_cost',
				'max_cost',
				'business_model',
				'industry_involved',
				'id'
			)
			->first();
		if($data['id']){
			if($data['industry_involved']){
				$group_id = (new SysDataDict())->getByCodeDict('SSHYT','id');
				$data['industry_name'] = (new SysDataDict())->getFieldByUseGroupValue($data['industry_involved'],$group_id['id']);
			}
			$business_model = [1=>'加盟',2=>'直营'];
			$businessmodel = $data['business_model']?explode(',',$data['business_model']):[];
			$logo = Db::table('sys_file')->where('id',$data['file_id'])->value('access_path');
			$data['logo'] = $logo;
			$data['business_model'] = '';
			if($businessmodel)
			{
				foreach ($businessmodel as $item){
					$data['business_model'].=$business_model[$item].'/';
				}
				$data['business_model'] = substr($data['business_model'],0,-1);
			}
		}
		return $data;
	}
}